home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1991 / Jan 91 / MacApp.Tech$ 1⁄25⁄91 / 2790-Re Failure Handling-Jan91 < prev    next >
Encoding:
Text File  |  1991-03-06  |  2.9 KB  |  92 lines  |  [TEXT/GEOL]

  1. Item    4527159                         24-Jan-91        10:40PST
  2.  
  3. From:   D3861                           Electronics for Imaging,Avi Bar,PRT
  4.  
  5. To:     POWERUP.ENG                     Power Up Software,PRT
  6.         MACAPP.TECH$                    MacApp Technical
  7.  
  8. ------------------------------------------------------------------------------
  9.  
  10. Sub:    Re: Failure Handling
  11.  
  12. James et al. --
  13.  
  14.  >no one seems to override TApplication.ShowError() to post any
  15.  >fancy error alerts.
  16.  
  17. I recently overrode TApplication.ShowError to add the error number to the
  18. dialog in one of the corners (much like Photoshop does).  We expect this to be
  19. very useful in gathering error information from beta testers and end users.
  20. (Although even more important is to provide sensible error string resources; it
  21. baffles me completely why Apple didn't include a real 'errs' resource and the
  22. associated 'STR#'.  I have had to add something like this to nearly every Mac
  23. application I've written.)  Unfortunately, the default mechanism goes through a
  24. few levels of global routine, so it requires taking the code from the final
  25. global routine and pasting it into your TApplication.ShowError override.  This
  26. is particularly unfortunate because it means I can't just distribute the hack,
  27. because it includes a significant amount of MacApp source code.
  28.  
  29. I can give you it in pieces.  Here's the alert filter:
  30.  
  31. {$S MAError}
  32.  
  33.    var
  34.    theError: integer;
  35.  
  36.    function MyErrAlertFilter (theDialog: DialogPtr; var theEvent: EventRecord;
  37. var itemHit: INTEGER): BOOLEAN;
  38.    var
  39.    s: Str255;
  40.    r: Rect;
  41.    info: FontInfo;
  42.    oldFont, oldSize: integer;
  43.    oldFace: Style;
  44.    save: GrafPtr;
  45.    begin
  46.    MyErrAlertFilter := MacAppAlertFilter(theDialog, theEvent, itemHit);
  47.    if (theEvent.what = updateEvt) & (theError <> noErr) then
  48.    begin { draw the error number in the lower left-hand corner }
  49.    GetPort(save);
  50.    SetPort(theDialog);
  51.    oldFont := theDialog^.txFont;
  52.    oldSize := theDialog^.txSize;
  53.    oldFace := theDialog^.txFace;
  54.    TextFont(applFont);
  55.    TextSize(9);
  56.    TextFace([]);
  57.    GetFontInfo(info);
  58.    NumToString(theError, s);
  59.    r := theDialog^.portRect;
  60.    r.left := r.left + 4;
  61.    r.bottom := r.bottom - 4;
  62.    r.top := r.bottom - (info.ascent + info.descent);
  63.    r.right := r.left + StringWidth(s);
  64.    TextBox(@s[1], length(s), r, teJustLeft);
  65.    TextFont(oldFont);
  66.    TextSize(oldSize);
  67.    TextFace(oldFace);
  68.    SetPort(save);
  69.    end;
  70.    end;
  71.  
  72. The ShowError override is just exactly like ErrorAlert, except that the line:
  73.  
  74.   StdAlert(alertID);
  75.  
  76. is changed to:
  77.  
  78.    theError := error;
  79.    reply := MacAppAlert(alertID, ProcPtr(@MyErrAlertFilter));
  80.  
  81. (Oh, and TApplication.ShowError calls its first argument "error", while
  82. ErrorAlert calls it "err", so I did a search-and-replace in the copied
  83. ErrorAlert code to change the argument name.)
  84.  
  85.  > no one seems to call Failure() directly
  86.  
  87. I do frequently, for various bad parameter and such like errors.
  88.  
  89. Tim Maroney
  90. Electronics for Imaging
  91.  
  92.